package com.homedo.odin.solution.enumcode.column;

import java.util.Arrays;
import lombok.Getter;

/**
 * @author: zhanglei
 * @date: 2018/4/17
 * @Description:
 */
@Getter
public enum SpecialColumnStatusEnum {

    UNPUBLISHED(10, "未发布"),
    ALREADY_RELEASED(20, "已发布"),
    DELETED(30, "已删除");

    private Integer dbValue;
    private String displayValue;

    SpecialColumnStatusEnum(Integer key, String displayValue) {
        this.displayValue = displayValue;
        this.dbValue = key;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(SpecialColumnStatusEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(SpecialColumnStatusEnum.values())
                .anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }


    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(SpecialColumnStatusEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
